package com.naizhuai.ui.rank;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.naizhuai.R;
import com.naizhuai.network.NetWorkObserver;
import com.naizhuai.ui.BaseFragment;
import com.naizhuai.ui.adapter.ManageDividerItemDecoration;
import com.naizhuai.ui.entity.User.RankData;
import com.naizhuai.ui.entity.User.UserRank;
import com.naizhuai.ui.fragment.BaseLazyFragment;
import com.naizhuai.ui.user.UserManageDataApiStoreIml;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import rx.functions.Action1;


public class TeamListFragment extends BaseRankFragment {
    @BindView(R.id.item_list)
    RecyclerView itemList;
    @BindView(R.id.user_rank)
    TextView userRank;
    @BindView(R.id.teamname)
    TextView teamname;
    @BindView(R.id.user_count)
    TextView userCount;
    Unbinder unbinder;
    private UserManageDataApiStoreIml mDataApiStoreIml;

    public static TeamListFragment newInstance() {
        TeamListFragment fragment = new TeamListFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mDataApiStoreIml == null) {
            mDataApiStoreIml = UserManageDataApiStoreIml.getInstance();
        }
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData();
    }

    private void initData() {
        showWaitDiaLog();

        loadGroupData("","");
    }

    private void loadGroupData(String key,String datekey) {
        mDataApiStoreIml.getGroup_Rank(key,datekey)
                .subscribe(getRankObserver());
    }


    @Override
    public void showSelfData(RankData rankData) {
        userRank.setText(rankData.rank);
        teamname.setText(rankData.departmentName);
        userCount.setText(rankData.totalCount);
    }

    @Override
    public void loadFragmentData(String key, String dateKey) {
        getChildFragmentManager().beginTransaction()
                .replace(R.id.item_detail_container, TeamDataFragment.newInstance(key, dateKey))
                .commit();
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.fragment_team_list;
    }

    @Override
    public void loadRankData(String key, String datekey) {
        loadGroupData("",datekey);
    }


}
